package com.acme.bankapp.domain.bank;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Bank client.
 *
 */
public class Client {
	private Gender gender;

	private String name;

	private Set<Account> accounts = new LinkedHashSet<Account>();

	/**
	 * Creates new client.
	 * @param gender client's gender
	 * @param name client's full name
	 */
	public Client(Gender gender, String name) {
		this.gender = gender;
		this.name = name;
	}

	/**
	 * Returns client salutation, i.e. "Mr. John Doe".
	 * @return client salutation
	 */
	public String getClientSalutation() {
		return gender.toString() + " " + this.getName();
	}

	/**
	 * Returns all client accounts.
	 * @return client accounts
	 */
	public Set<Account> getAccounts() {
		return new LinkedHashSet<Account>(accounts);
	}

	/**
	 * Assigns another account to the client.
	 * @param account account
	 */
	public void addAccount(Account account) {
		accounts.add(account);
	}

	/**
	 * Returns client's gender.
	 * @return client gender
	 */
	public Gender getGender() {
		return gender;
	}

	/**
	 * Returns client's name.
	 * @return client name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @inheritDoc
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj != null && obj instanceof Client) {
			Client anotherClient = (Client)obj;
			return this.name.equals(anotherClient.name) && this.gender.equals(anotherClient.gender);
		} else {
			return false;
		}
	}
	
	/**
	 * @inheritDoc
	 */
	@Override
	public int hashCode() {
		return getClientSalutation().hashCode();
	}
}